package com.sitia.jd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sitia.jd.domain.MxGoodsType;
import com.sitia.jd.service.IMxGoodsTypeService;
import com.sitia.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sitia.common.annotation.Log;
import com.sitia.common.core.controller.BaseController;
import com.sitia.common.core.domain.AjaxResult;
import com.sitia.common.enums.BusinessType;

import com.sitia.common.core.page.TableDataInfo;

/**
 * 商品类型Controller
 * 
 * @author sitia
 * @date 2023-05-22
 */
@RestController
@RequestMapping("/jd/type")
public class MxGoodsTypeController extends BaseController
{
    @Autowired
    private IMxGoodsTypeService mxGoodsTypeService;

    /**
     * 查询商品类型列表
     */
   // @PreAuthorize("@ss.hasPermi('jd:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(MxGoodsType mxGoodsType)
    {
        startPage();
        List<MxGoodsType> list = mxGoodsTypeService.selectMxGoodsTypeList(mxGoodsType);
        return getDataTable(list);
    }

    /**
     * 导出商品类型列表
     */
   // @PreAuthorize("@ss.hasPermi('jd:type:export')")
    @Log(title = "商品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MxGoodsType mxGoodsType)
    {
        List<MxGoodsType> list = mxGoodsTypeService.selectMxGoodsTypeList(mxGoodsType);
        ExcelUtil<MxGoodsType> util = new ExcelUtil<MxGoodsType>(MxGoodsType.class);
        util.exportExcel(response, list, "商品类型数据");
    }

    /**
     * 获取商品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('jd:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mxGoodsTypeService.selectMxGoodsTypeById(id));
    }

    /**
     * 新增商品类型
     */
   @PreAuthorize("@ss.hasPermi('jd:type:add')")
    @Log(title = "商品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MxGoodsType mxGoodsType)
    {
        return toAjax(mxGoodsTypeService.insertMxGoodsType(mxGoodsType));
    }

    /**
     * 修改商品类型
     */
    @PreAuthorize("@ss.hasPermi('jd:type:edit')")
    @Log(title = "商品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MxGoodsType mxGoodsType)
    {
        return toAjax(mxGoodsTypeService.updateMxGoodsType(mxGoodsType));
    }

    /**
     * 删除商品类型
     */
    @PreAuthorize("@ss.hasPermi('jd:type:remove')")
    @Log(title = "商品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mxGoodsTypeService.deleteMxGoodsTypeByIds(ids));
    }
}
